#!/bin/sh
SEARCH=$1
URL=$2
REPOPATH=$3
USERNAME=$4
svn checkout -q $URL $REPOPATH --username $USERNAME
svn log $REPOPATH -v | awk '{
  if ( $1 == "------------------------------------------------------------------------") {
	#get information
    getline
    REVISION = substr($1,2)
    COMITTER = $3
    DATE = $5
    LINES = $13	
  }
  else {
	
	if($0 == "Changed paths:"){
		#get all file change
		getline
		FILE=substr($0,index($0,$1)+2) ":" $1 ":" REVISION
		while(getline>0 && $0 != ""){
			FILE=FILE "\n" substr($0,index($0,$1)+2) ":" $1 ":" REVISION
		} 
	}
	#match search
    if ($1 == SEARCH) {
		#split file to get head revision
		n=split(FILE,array,"\n");
		for (i=1;i<=n;i++) {
			#get file name
			m=split(array[i],file,":");
			#get head revision
			cmd = "svn info \"" REPOPATH file[1] "\" |grep \"Last Changed Rev:\" |cut -c19-" 
			cmd| getline headrevision
			close(cmd)
			#output result
			print array[i] ":" headrevision
		}
	  
    }
  }

}' SEARCH="$SEARCH" REPOPATH="$REPOPATH"